package com.ai.enviro.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.nio.charset.StandardCharsets;

public class EncryptUtils {
    public static String getMD5Hash(String input) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        byte[] hashInBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));

        // Convert byte array to a hexadecimal string
        StringBuilder hexStringBuilder = new StringBuilder(2 * hashInBytes.length);
        for (byte b : hashInBytes) {
            hexStringBuilder.append(String.format("%02x", b & 0xff));
        }

        return hexStringBuilder.toString();
    }

}
